import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  // {
  //   path: '/',
  //   component: () => import('@/views/app/index'),
  //   hidden: true
  // },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    redirect: '/home_page'
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/role',
    component: () => import('@/views/role/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home_page',
    menu_rel: 'homepage',
    children: [
      {
        path: 'home_page',
        component: () => import('@/views/home_page/index'),
        name: 'Homepage',
        meta: { title: '首页', icon: 'dashboard', affix: false }
      }
    ]
  },
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/pajx/sys/menu',
    component: Layout,
    menu_rel: 'pajx/sys/menu',
    children: [
      {
        path: '/pajx/sys/menu',
        component: () => import('@/views/pajx/sys/menu'),
        name: 'SysMenu',
        meta: { title: '菜单管理' }
      }
    ]
  },
  {
    path: '/pajx/sys/dept',
    component: Layout,
    menu_rel: 'pajx/sys/dept',
    children: [
      {
        path: '/pajx/sys/dept',
        component: () => import('@/views/pajx/sys/dept'),
        name: 'SysDept',
        meta: { title: '部门管理' }
      }
    ]
  },
  {
    path: '/pajx/sys/role',
    component: Layout,
    menu_rel: 'pajx/sys/role',
    children: [
      {
        path: '/pajx/sys/role',
        component: () => import('@/views/pajx/sys/role'),
        name: 'SysRole',
        meta: { title: '角色管理' }
      }
    ]
  },
  {
    path: '/pajx/sys/user_inside',
    component: Layout,
    menu_rel: 'pajx/sys/user_inside',
    children: [
      {
        path: '/pajx/sys/user_inside',
        component: () => import('@/views/pajx/sys/user_inside'),
        name: 'SysUserInside',
        meta: { title: '内部用户' }
      }
    ]
  },
  {
    path: '/pajx/sys/perm',
    component: Layout,
    menu_rel: 'pajx/sys/perm',
    children: [
      {
        path: '/pajx/sys/perm',
        component: () => import('@/views/pajx/sys/perm'),
        name: 'SysPerm',
        meta: { title: '权限管理' }
      }
    ]
  },
  {
    path: '/pajx/sys/app',
    component: Layout,
    menu_rel: 'pajx/sys/app',
    children: [
      {
        path: '/pajx/sys/app',
        component: () => import('@/views/pajx/sys/app'),
        name: 'SysApp',
        meta: { title: '应用管理' }
      }
    ]
  },
  {
    path: '/pajx/sys/dic',
    component: Layout,
    menu_rel: 'pajx/sys/dic',
    children: [
      {
        path: '/pajx/sys/dic',
        component: () => import('@/views/pajx/sys/dic'),
        name: 'SysDic',
        meta: { title: '字典管理' }
      }
    ]
  },{
    path: '/pajx/server/server',
    component: Layout,
    menu_rel: 'pajx/server/server',
    children: [
      {
        path: '/pajx/server/server',
        component: () => import('@/views/pajx/server/server'),
        name: 'pajxServer',
        meta: { title: '服务器管理' }
      }
    ]
  },{
    path: '/pajx/server/container',
    component: Layout,
    menu_rel: 'pajx/server/container',
    children: [
      {
        path: '/pajx/server/container',
        component: () => import('@/views/pajx/server/container'),
        name: 'pajxServer',
        meta: { title: '容器管理' }
      }
    ]
  },{
    path: '/pajx/server/image',
    component: Layout,
    menu_rel: 'pajx/server/image',
    children: [
      {
        path: '/pajx/server/image',
        component: () => import('@/views/pajx/server/image'),
        name: 'pajxServer',
        meta: { title: '镜像管理' }
      }
    ]
  },{
    path: '/pajx/server/log',
    component: Layout,
    menu_rel: 'pajx/server/log',
    children: [
      {
        path: '/pajx/server/log',
        component: () => import('@/views/pajx/server/log'),
        name: 'pajxServer',
        meta: { title: '日志分析' }
      }
    ]
  },
  // {
  //   path: '/pajx/pajx/product',
  //   component: Layout,
  //   menu_rel: 'pajx/pajx/product',
  //   children: [
  //     {
  //       path: '/pajx/pajx/product',
  //       component: () => import('@/views/pajx/pajx/product'),
  //       name: 'PajxProduct',
  //       meta: { title: '产品类型' }
  //     }
  //   ]
  // },
  // {
  //   path: '/pajx/pajx/equip',
  //   component: Layout,
  //   menu_rel: 'pajx/pajx/equip',
  //   children: [
  //     {
  //       path: '/pajx/pajx/equip',
  //       component: () => import('@/views/pajx/pajx/equip'),
  //       name: 'PajxEquip',
  //       meta: { title: '设备列表' }
  //     }
  //   ]
  // },
  // {
  //   path: '/pajx/pajx/student',
  //   component: Layout,
  //   menu_rel: 'pajx/pajx/student',
  //   children: [
  //     {
  //       path: '/pajx/pajx/student',
  //       component: () => import('@/views/pajx/pajx/student'),
  //       name: 'PajxStudent',
  //       meta: { title: '学生管理' }
  //     }
  //   ]
  // },
  // {
  //   path: '/pajx/pajx/student_card',
  //   component: Layout,
  //   menu_rel: 'pajx/pajx/student_card',
  //   children: [
  //     {
  //       path: '/pajx/pajx/student_card',
  //       component: () => import('@/views/pajx/pajx/student_card'),
  //       name: 'PajxStudentCard',
  //       meta: { title: '读卡与挂失' }
  //     }
  //   ]
  // },
  // {
  //   path: '/pajx/pajx/class',
  //   component: Layout,
  //   menu_rel: 'pajx/pajx/class',
  //   children: [
  //     {
  //       path: '/pajx/pajx/class',
  //       component: () => import('@/views/pajx/pajx/class'),
  //       name: 'PajxClass',
  //       meta: { title: '班级年级管理' }
  //     }
  //   ]
  // },
  // {
  //   path: '/pajx/pajx/teacher',
  //   component: Layout,
  //   menu_rel: 'pajx/pajx/teacher',
  //   children: [
  //     {
  //       path: '/pajx/pajx/teacher',
  //       component: () => import('@/views/pajx/pajx/teacher'),
  //       name: 'PajxTeacher',
  //       meta: { title: '教师列表' }
  //     }
  //   ]
  // },
  // {
  //   path: '/pajx/pajx/teacher_card',
  //   component: Layout,
  //   menu_rel: 'pajx/pajx/teacher_card',
  //   children: [
  //     {
  //       path: '/pajx/pajx/teacher_card',
  //       component: () => import('@/views/pajx/pajx/teacher_card'),
  //       name: 'PajxTeacherCard',
  //       meta: { title: '读卡与挂失' }
  //     }
  //   ]
  // },
  // {
  //   path: '/pajx/pajx/batch_update',
  //   component: Layout,
  //   menu_rel: 'pajx/pajx/batch_update',
  //   children: [
  //     {
  //       path: '/pajx/pajx/batch_update',
  //       component: () => import('@/views/pajx/pajx/batch_update'),
  //       name: 'PajxBatchUpdate',
  //       meta: { title: '批量更新' }
  //     }
  //   ]
  // },
  // {
  //   path: '/pajx/pajx/batch_cardsn',
  //   component: Layout,
  //   menu_rel: 'pajx/pajx/batch_cardsn',
  //   children: [
  //     {
  //       path: '/pajx/pajx/batch_cardsn',
  //       component: () => import('@/views/pajx/pajx/batch_cardsn'),
  //       name: 'PajxBatchCardsn',
  //       meta: { title: '批量更新卡内码' }
  //     }
  //   ]
  // }
]

const createRouter = () => {
  return new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    base: '/',
    routes: constantRoutes
  })
}

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
